import json
import requests
import re


def get(msg):
    # 正则匹配需要查找的词
    pattern = re.compile(r'(.+)的近义词')
    keyWord = pattern.findall(msg)[0]

    response = requests.get(
        url='https://wantwords.thunlp.org/ChineseRD/?description=' + keyWord + '&mode=CC')
    result = json.loads(response.text)

    str = keyWord + '的近义词有：\n'
    for i in range(5):
        str = str + result[i]['w'] + '\n'
    str = str.strip()
    return str


if __name__ == '__main__':
    print(get('测试的近义词'))
